using NUnit.Framework;
using NUnit.Framework.SyntaxHelpers;
using QuickTest.Core.Compilation;
using QuickTest.Services.TextRetrieval;
using Rhino.Mocks;

namespace QuickTest.Tests.Core.Compilation
{
    [TestFixture]
    public class SolutionCompilerTests
    {
        private const string FilePath = "c:/";
        private static readonly string FullFilePath = string.Format("{0}TestSolution.sln", FilePath);
        private const string MultipleProject2008SolutionResourcePath = "QuickTest.Tests,QuickTest.Tests.Core.Compilation.Artifacts.MultipleProject2008.sln";

        [Test]
        [Category("Integration")]
        public void Compile_compiles_all_projects_in_solution()
        {
            var projectCompiler = MockRepository.GenerateMock<ICompilable<Project>>();
            var solutionCompiler = new CompileSolution(projectCompiler);

            Solution solution = GetTestSolution(MultipleProject2008SolutionResourcePath);

            var compiler = MockRepository.GenerateStub<ICompiler>();
            var outputDirectory = new DirectoryUri(@"c:\temp\");

            projectCompiler.Expect(c => c.Compile(null, compiler, outputDirectory))
                .IgnoreArguments()
                .Repeat.Times(solution.Projects.Count);

            solutionCompiler.Compile(solution, compiler, outputDirectory);

            projectCompiler.VerifyAllExpectations();
        }

        private static Solution GetTestSolution(string embeddedResourcePath)
        {
            var settings = new EmbeddedResourceTextRetrieverSettings(embeddedResourcePath);
            return Solution.Create(new FileUri(FullFilePath), new EmbeddedResourceTextRetriever(settings));
        }
    }
}